﻿using ArtMath.Attribute;
using ArtMath.Component.Polygon;
using ArtMath.Core.Data;
using ArtMath.Core.Helper;
using ArtMath.Setting;
using System;
using System.ComponentModel;
using System.Drawing;

namespace ArtMath.Component.Point
{
    /// <summary>
    /// 三角形垂心基类
    /// </summary>
    [Serializable]
    public abstract class OrthoCenterBase : ConstructedPointBase
    {
        public OrthoCenterBase(SketchPad pad, string name, PolygonBase triangle, bool addToList = true) : base(pad, name, ToolTypeName.sjxcx, addToList)
        {
            OutHosts = new LineBase[1];
            Triangle = triangle;
            OutlineColor = Settings.Instance.OrthoCenterPointOutlineColor;
            FillColor = Settings.Instance.OrthoCenterPointFillColor;
        }
        [DefaultValue(typeof(Color), "91, 155, 213")]
        public override Color OutlineColor
        {
            get
            {
                return base.OutlineColor;
            }

            set
            {
                base.OutlineColor = value;
            }
        }
        [DefaultValue(typeof(Color), "234, 239, 247")]
        public override Color FillColor
        {
            get
            {
                return base.FillColor;
            }

            set
            {
                base.FillColor = value;
            }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("Triangle")]
        public PolygonBase Triangle
        {
            get { return OutHosts[0] as PolygonBase; }
            set
            {
                if (value is PolygonBase)
                {
                    SetLine(0, value);
                }
            }
        }
        public override PointD GetNewLocationAfterOutHostChanged(bool getXY = false)
        {
            TriangleBase tb = Triangle as TriangleBase;
            if (tb != null)
            {
                return getXY ? tb.NewOrthoCenter : tb.NewPOrthoCenter;
            }
            else
            {
                if (Triangle.Lines.Count == 3)
                {
                    PointD xy = Utility.GetOrthoCenter(Triangle.InPoints[0].NewXY, Triangle.InPoints[1].NewXY, Triangle.InPoints[2].NewXY);
                    return getXY ? xy : Pad.XYToPxy(xy);
                }
            }
            return base.GetNewLocationAfterOutHostChanged(getXY);
        }
        public override void ConvertType(ToolTypeName targetType)
        {
            if (targetType != ToolType) return;
            OrthoCenterBase targetPoint = null;
            SimulateDeleted(() =>
            {
                if (Pad.CoordinateType == CoordinateSystemType.PolarCoordinate)
                {
                    targetPoint = new POrthoCenter(Pad, Name, Triangle, false);
                }
                else
                {
                    targetPoint = new ROrthoCenter(Pad, Name, Triangle, false);
                }
            });
            afterGenerateNewType(targetPoint);
        }
    }
}
